package c.x.jy.dao.dao;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@Mapper 
public interface CommonDao  extends BaseMapper {
	
    @Select(" SELECT identityCard,area FROM `t_area`")
	List<Map<String, Object>> selectAreaList();

    
    @Select("${sql}${id}")
	String selectData(String sql, Long id);

    @Select("select (SELECT count(*) FROM `t_order` where `status` =0 and (${businessId} =0 or business_id=${businessId} ) )as waittingPayNum," +
            " (SELECT count(*) FROM `t_order` where `status` =1 and (${businessId} =0 or business_id=${businessId} )  )as serviceingNum," +
            " (SELECT count(*) FROM `t_order` where `status` =2 and (${businessId} =0 or business_id=${businessId} )  )as waittingforevaluateNum," +
            "(SELECT count(*) FROM `t_order` where `status` =2 and (${businessId} =0 or business_id=${businessId} )  )as doneNum,  " +
            "( select  IFNULL(sum(discount_price),0) from t_order_bill b WHERE b.create_date>=CURDATE() and b.status=1 and (${businessId} =0 or business_id=${businessId} )  ) as todayprice, " +
            "( select  IFNULL(sum(discount_price),0) from t_order_bill b WHERE  b.status=1 and b.create_date>=  DATE_SUB(curdate(),INTERVAL 1 DAY) and b.create_date<CURDATE() and (${businessId} =0 or business_id=${businessId} )  )as yestodayprice," +
            "( select  IFNULL(sum(discount_price),0) from t_order_bill b WHERE  b.status=1 and b.create_date>=  DATE_ADD(curdate(),interval -day(curdate())+1 day) and (${businessId} =0 or business_id=${businessId} )    )as thismonthprice," +
            "( select  IFNULL(sum(discount_price),0) from t_order_bill b WHERE  b.status=1 and (${businessId} =0 or business_id=${businessId} )   )as totalprice," +
            "(SELECT count(*) FROM `t_order` b where `status`>0 and b.create_date>=CURDATE()  and  (${businessId} =0 or business_id=${businessId} )   )as todayOrdernum," +
            "(SELECT count(*) FROM `t_order` b where `status`>0 and  b.create_date>=  DATE_SUB(curdate(),INTERVAL 1 DAY) and b.create_date<CURDATE()   and  (${businessId} =0 or business_id=${businessId} )   )as yestodayOrdernum," +
            "(SELECT count(*) FROM `t_order` b where `status`>0 and  b.create_date>=  DATE_ADD(curdate(),interval -day(curdate())+1 day) and  (${businessId} =0 or business_id=${businessId} )   )as thismonthOrdernum  from dual ")
    Map selectStatistics(    Long businessId);
    @Select("SELECT sum(b.discount_price) as price, count(    b.order_id ) as count, Date(min(b.create_date))  AS date " +
            " FROM  t_order_bill b where status>0  and (${businessId} =0 or business_id=${businessId} ) GROUP BY  Date(b.create_date) ")
    List<Map<String, Object>> echartsZhu(Long businessId, String begintime, String endtime);
  @Select("SELECT IFNULL(count(1),0) as count  , item_type as type ,CASE t.item_type WHEN 1 THEN CONCAT('咨询:',max(item_name)) WHEN 2 THEN CONCAT('闪测:',max(item_name))" +
          "  WHEN 3 THEN CONCAT('提问:',max(item_name))  WHEN 4 THEN  CONCAT('充值:',max(item_name)) ELSE CONCAT('会员认证:',max(item_name)) END AS name" +
          " FROM `t_order_items` t LEFT JOIN t_order o on o.id=t.order_id WHERE     (${businessId} =0 or business_id=${businessId} )  GROUP BY item_type,item_name")
    List<Map<String, Object>> echartsBin(Long businessId, String begintime, String endtime);
}
